/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datas;

import beans.UserWeb;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author havn
 */
public class UserWebObj {

    private connector con;

    public UserWebObj() {
        con = new connector();
    }

    public UserWeb login(String struser, String pass) {
        try {
            CallableStatement call = con.getCon().prepareCall("{call CheckLogin(?,?)}");
            call.setString(1, struser);
            call.setString(2, pass);
            ResultSet rs = call.executeQuery();
            if(rs.next()){
                UserWeb user = new UserWeb();
                user.setId(rs.getInt("id"));
                user.setUsername(rs.getString("username"));
                user.setFullname(rs.getString("fullname"));
                user.setAge(rs.getInt("age"));
                return user;
            }else{
                return null;
            }
        } catch (SQLException ex) {
            ex.getStackTrace();
        }
        return null;
    }
}
